qrisp.QuantumFloat.quantum_bit_shift#

QuantumFloat.quantum_bit_shift(shift_amount)[source]#

Performs a bit shift in the quantum device. While exp_shift performs a bit shift in the compiler (thus costing no quantum gates) this method performs the bitshift on the hardware.

This has the advantage, that it can be controlled if called within a ControlEnvironment and furthermore admits bit shifts based on the state of a QuantumFloat

Note

Bit bit shifts based on a QuantumFloat are currently only possible if both self and shift_amount are unsigned.

Warning

Quantum bit shifting extends the QuantumFloat (ie. it allocates additional qubits).

Parameters:
shift_amountint or QuantumFloat

The amount to shift.

Raises:
Exception

Tried to shift QuantumFloat exponent by non-integer value

Exception

Quantum-quantum bitshifting is currently only supported for unsigned arguments

Examples

We create a QuantumFloat and a QuantumBool to perform a controlled bit shift.

from qrisp import QuantumFloat, QuantumBool, h
qf = QuantumFloat(4)
qf[:] = 1
qbl = QuantumBool()
h(qbl)

with qbl:
    qf.quantum_bit_shift(2)

Evaluate the result

>>> print(qf.qs.statevector())
sqrt(2)*(|1>*|False> + |4>*|True>)/2